import java.util.ArrayList;

public class Node {
    private Pairs node;
    private ArrayList<Node> children;
    
    public Node(Pairs pairs,ArrayList<Node> children) {
        this.node = pairs;
        this.children = children;
    }
    
    public void addChild(Node node) {
        children.add(node);
    }

    public Pairs getPair() {
        return this.node;
    }

    public ArrayList<Node> getChildren() {
        return children;
    }

    public boolean isEnd() {
        return children == null || children.isEmpty();
    }
    
    public String toString() {
        if (isEnd()) {
            return node.toString();
        } else {
            String s = "";
            for (Node i : children) {
                if (i == null) {
                    continue;
                }
                s += i.toString();
            }
            s += node.toString();
            return s;
        }
    }
    
}
